<template>
  <div class="custom-body">
    <div v-if="showHeader" class="custom-header">
      <!-- :style="titleStyle" -->
      <div class="header-body">
        <div v-if="temp.sfxs === true" class="header-icon">
          <i :class="temp.lmtb" />
        </div>
        <el-image :src="require('@/assets/images/notice.png')" />
        <div class="header-title">
          <span class="title-span">{{ temp.lmmc }}</span>
        </div>
        <div v-if="temp.isMore === true" class="header-icon" @click="callBack">
          <span class="more-span">more</span>
        </div>
      </div>
    </div>
    <div class="custom-content">
      <el-empty
        v-if="dataList === null || dataList.length === 0"
        :image-size="100"
      />
      <div v-else>
        <div
          v-for="(obj, index) in dataList"
          :key="'obj-' + index"
          class="custom-ul-li"
          :style="active === index ? activeStyle : borderColumn"
          @mouseenter="openAlert(index)"
          @mouseleave="closeAlert(index)"
          @click="openEntity(obj)"
        >
          <div class="custom-ul-li-title">{{ obj[column["title"]] }}</div>
          <div class="custom-ul-li-button">
            <div class="custom-li-button">{{ obj[column["left"]] }}</div>
            <div class="custom-li-time">{{ obj[column["time"]] }}</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { template, openEntity } from '@/mixins/template';
export default {
  name: 'PcNewListTempV2', // 学校通知学校迎新列表,单个学校迎新的更多组件
  mixins: [template, openEntity],
  props: {
    temp: {
      type: Object,
      default() {
        return {};
      }
    },
    showHeader: {
      type: Boolean,
      default: true
    },
    layout: {
      type: Object,
      default: () => {
        return {};
      }
    }
  },
  computed: {
    themes() {
      return this.$store.getters.theme;
    }
  },
  watch: {
    layout: {
      handler(newData, oldData) {
        this.customStyle = newData;
        /* this.titleStyle = { backgroundColor: newData.mrlb, opacity: newData.tmd }
        this.titleFont = { color: newData.lmys }
        this.activeStyle = { color: newData.xsys, backgroundColor: newData.xzbjs } */
      },
      immediate: true, // 父组件第一次传值时，执行handler，false则第一次不执行
      deep: false // formType为对象时，设置为true，此属性监听对象发生变化
    },
    temp: {
      handler(newData, oldData) {
        if (this.showHeader) {
          const pzx = JSON.parse(newData.data.pzx);
          this.setting = pzx;
          this.column = pzx;
          if (pzx.isRefresh !== undefined && pzx.isRefresh === true) {
            this.isRefresh = pzx.isRefresh;
          }
          if (pzx.refreshTime !== undefined && pzx.refreshTime !== null) {
            this.refreshTime = pzx.refreshTime;
          }
          this.cid = newData.data.id;
          this.initData();
        } else {
          const pzx = JSON.parse(newData.pzx);
          this.setting = pzx;
          if (pzx.isRefresh !== undefined && pzx.isRefresh === true) {
            this.isRefresh = pzx.isRefresh;
          }
          if (pzx.refreshTime !== undefined && pzx.refreshTime !== null) {
            this.refreshTime = pzx.refreshTime;
          }
          this.column = pzx;
          this.cid = newData.id;
          console.log('测试', this.column);
          this.initData();
        }
      },
      immediate: true, // 父组件第一次传值时，执行handler，false则第一次不执行
      deep: false // formType为对象时，设置为true，此属性监听对象发生变化
    },
    themes: {
      handler(val, oldVal) {
        this.borderStyle.borderRadius = val.bkdx;
        if (this.temp.sfxsbk === true) {
          this.borderStyle.border = '1px solid ' + val.bkys;
        }
        if (this.temp.bkyy === true) {
          this.borderStyle.boxShadow = '0 2px 4px rgba(0, 0, 0, .12)';
        }
        this.borderStyle.background = val.columnGroundColor;
        this.borderStyle.color = val.fontColor;
        this.titleStyle.background = val.columnTitleGroundColor;
        this.titleStyle.color = val.columnTitleFontColor;
        this.activeStyle.color = val.changeFontColor;
        // this.activeStyle.background = val.changeBackGroundColor;
        this.activeStyle.borderBottom = '1px solid ' + val.bkys;
        this.borderColumn.padding = '0px 10px';
        this.borderColumn.borderBottom = '1px solid ' + val.bkys;
        this.borderColumn = Object.assign({}, this.borderColumn);
        this.activeStyle = Object.assign({}, this.activeStyle);
        this.titleStyle = Object.assign({}, this.titleStyle);
        this.borderStyle = Object.assign({}, this.borderStyle);
      },
      immediate: true, // 父组件第一次传值时，执行handler，false则第一次不执行
      deep: false // formType为对象时，设置为true，此属性监听对象发生变化
    }
  },
  mounted() {
    window.addEventListener(
      'storage',
      e => {
        // e只是一个传参
        // 获取被修改的键值
        if (e.key == 'themes') {
          // 分别打印会发现内容一致
          // console.log(e.storageArea.themes);
          console.log(localStorage.themes);
          this.$store
            .dispatch('GetThemes')
            .then(res => {
              return true;
            })
            .catch(error => {
              console.log(error);
            });
          // this.$store.getters.theme = JSON.parse(localStorage.themes);
        }
      },
      false
    );
  }
};
</script>

<style scoped>
.custom-body {
  width: 100%;
  height: 100%;
  position: relative;
  display: flex;
  flex-flow: column nowrap;
  background-color: #ffffff;
  border-radius: 4px;
  padding: 0px 0px 10px 0px;
  box-sizing: border-box;
  overflow: hidden;
  box-shadow: #409eff;
  box-shadow: rgba(0, 0, 0, 0.12) 0px 2px 4px;
}
.custom-header {
  width: 100%;
  height: 40px;
  flex: 0 1 auto;
  padding: 0px 10px;
  box-sizing: border-box;
  line-height: 40px;
  cursor: pointer;
  color: #409eff;
}
.header-body {
  width: 100%;
  height: 41px;
  display: flex;
  flex-flow: row nowrap;
}

.header-icon {
  width: 45px;
  height: 45px;
  flex: 0 1 auto;
  text-align: center;
}
.more-span {
  display: block;
  height: 20px;
  width: 45px;
  border-radius: 10px;
  margin-top: 13px;
  line-height: 15px;
  text-align: center;
  cursor: pointer;
  color: #409eff;
  border: 1px solid #409eff;
}

.header-title {
  height: 40px;
  flex: 1 1 auto;
}
.title-span {
  height: 40px;
  padding: 12px 5px;
  box-sizing: border-box;
  line-height: 40px;
  text-align: center;
  position: relative;
}
.custom-content {
  width: 100%;
  height: auto;
  flex: 1 1 auto;
  padding: 0px 10px;
  overflow: hidden;
  box-sizing: border-box;
}
.custom-ul-li {
  width: 100%;
  height: 76px;
  display: flex;
  flex-flow: column nowrap;
  cursor: pointer;
  padding: 0px 10px;
}
.custom-ul-li-title {
  flex: 0 1 auto;
  height: 40px;
  line-height: 40px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
}
.custom-ul-li-title:hover {
  color: #c51c1c;
}
.custom-ul-li-button {
  flex: 0 1 auto;
  height: 36px;
  display: flex;
  flex-flow: row nowrap;
}
.custom-li-button {
  flex: 1 1 auto;
  overflow: hidden;
  line-height: 20px;
  font-size: 12px;
  color: #9fa8b5;
}
.custom-li-time {
  flex: 0 1 auto;
  height: 36px;
  line-height: 36px;
  text-align: right;
  font-size: 12px;
  color: #9fa8b5;
}
[class*="el-col-"] {
  float: left;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.header-body ::v-deep .el-image {
  width: 25px;
  height: 25px;
  margin-top: 8px;
}
</style>
